package com.suncreate.zhtz.iot.service.impl;

import com.suncreate.zhtz.iot.model.Ocrtable4;
import com.suncreate.zhtz.iot.mapper.Ocrtable4Dao;
import com.suncreate.zhtz.iot.service.Ocrtable4Service;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;

/**
 * (Ocrtable4)表服务实现类
 *
 * @author makejava
 * @since 2021-09-08 10:10:26
 */
@Service("ocrtable4Service")
public class Ocrtable4ServiceImpl implements Ocrtable4Service {
    @Resource
    private Ocrtable4Dao ocrtable4Dao;

    /**
     * 通过ID查询单条数据
     *
     * @param dtime 主键
     * @return 实例对象
     */
    @Override
    public Ocrtable4 queryById(Date dtime) {
        return this.ocrtable4Dao.queryById(dtime);
    }

    /**
     * @return 实例对象
     */
    @Override
    public Ocrtable4 getDataByLimit() {
        return this.ocrtable4Dao.getDataByLimit();
    }

    /**
     * @return 实例对象
     */
    @Override
    public Ocrtable4 getDataByTimeLimit(Date dtime) {
        return this.ocrtable4Dao.getDataByTimeLimit(dtime);
    }

    /**
     * 分页查询
     *
     * @param ocrtable4 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Ocrtable4> queryByPage(Ocrtable4 ocrtable4, PageRequest pageRequest) {
        long total = this.ocrtable4Dao.count(ocrtable4);
        return new PageImpl<>(this.ocrtable4Dao.queryAllByLimit(ocrtable4, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param ocrtable4 实例对象
     * @return 实例对象
     */
    @Override
    public Ocrtable4 insert(Ocrtable4 ocrtable4) {
        this.ocrtable4Dao.insert(ocrtable4);
        return ocrtable4;
    }

    /**
     * 修改数据
     *
     * @param ocrtable4 实例对象
     * @return 实例对象
     */
    @Override
    public Ocrtable4 update(Ocrtable4 ocrtable4) {
        this.ocrtable4Dao.update(ocrtable4);
        return this.queryById(ocrtable4.getDtime());
    }

    /**
     * 通过主键删除数据
     *
     * @param dtime 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Date dtime) {
        return this.ocrtable4Dao.deleteById(dtime) > 0;
    }
}
